package cn.com.xyzq.reks.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;

@Entity
@Table(name = "order_client")
@XmlRootElement
public class OrderClient extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8453425402530145239L;

	private Long id;
	private Staff staff;
	private Integer clientId;
	private String clientName;
	private String orderType;
	private String source;
	private String introducer;
	private String introducerCell;
	private Date orderDate;
	private Timestamp subDatetime;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE })
	@JoinColumn(name = "staff_id")
	public Staff getStaff() {
		return staff;
	}

	@Column(name = "client_id")
	public Integer getClientId() {
		return clientId;
	}

	@Column(name = "client_name", length = 20)
	public String getClientName() {
		return clientName;
	}

	@Column(name = "order_type", columnDefinition = "enum('account','paper','fund','paperSh','paperSz','commodityFutures','indexFutures','marginAccount')")
	public String getOrderType() {
		return orderType;
	}

	@Column(name = "source", columnDefinition = "enum('bank','self','otherPipe')")
	public String getSource() {
		return source;
	}

	@Column(name = "introducer", length = 50)
	public String getIntroducer() {
		return introducer;
	}

	@Column(name = "introducer_cell", length = 50)
	public String getIntroducerCell() {
		return introducerCell;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "order_date", length = 10)
	public Date getOrderDate() {
		return orderDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "sub_datetime", length = 10)
	public Timestamp getSubDatetime() {
		return subDatetime;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public void setClientId(Integer clientId) {
		this.clientId = clientId;
	}

	public void setClientName(String clientName) {
		this.clientName = clientName;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public void setIntroducer(String introducer) {
		this.introducer = introducer;
	}

	public void setIntroducerCell(String introducerCell) {
		this.introducerCell = introducerCell;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public void setSubDatetime(Timestamp subDatetime) {
		this.subDatetime = subDatetime;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
				.append("staff", staff)
				.append("client id", clientId)
				.append("client name", clientName)
				.append("order type", orderType)
				.append("introducer", introducer)
				.append("introducer Cell", introducerCell)
				.append("oredr date", orderDate)
				.append("sub datetime", subDatetime).toString();

	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		if (this == o) {
			return true;
		}
		if (!(o instanceof OrderClient)) {
			return false;
		}
		final OrderClient oc = (OrderClient) o;
		return oc.hashCode() == this.hashCode();
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		int result;
		result = (id != null ? id.hashCode() : 0);
		result = 29 * result + (staff != null ? staff.hashCode() : 0);
		result = 29 * result + (clientId != null ? clientId.hashCode() : 0);
		result = 29 * result + (clientName != null ? clientName.hashCode() : 0);
		result = 29 * result + (orderType != null ? orderType.hashCode() : 0);
		result = 29 * result + (source != null ? source.hashCode() : 0);
		result = 29 * result + (introducer != null ? introducer.hashCode() : 0);
		result = 29 * result
				+ (introducerCell != null ? introducerCell.hashCode() : 0);
		result = 29 * result + (orderDate != null ? orderDate.hashCode() : 0);
		result = 29 * result
				+ (subDatetime != null ? subDatetime.hashCode() : 0);
		return result;
	}

}
